home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 26 / pascal / sprite.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1986-06-19  |  3.3 KB  |  91 lines

  1. PROGRAM sprites ;
  2. { this is an example of using two screens, one off screen to save stuff }
  3. { draws a box on a medium rez screen then copies it to an off screen buffer
  4.   in a new location.  Then it copies it back to the physical screen }
  5.  
  6. { by Ron Rautenberg  72777,2277         May 1986
  7.      15 San Juan Dr
  8.      Salinas, Ca 93901
  9.         408-757-6481 }
  10.  
  11.   CONST
  12.     {$I GEMCONST.PAS}
  13.     box_x = 100; box_y = 50;    { dimensions of our box }
  14.     box_wid = 64; box_ht = 20;
  15.  
  16.     new_x = 200; new_y = 100;   { where we're going to move it to }
  17.  
  18.   TYPE
  19.     {$I gemtype.pas}
  20.  
  21.                 { this is for our off screen buffer }
  22.    scrn_memory = array[1..16000] of integer;
  23.  
  24.                 { MFDB for raster copies - must be an array, not a record }
  25.                 { apparantly records aren't allocated sequentially in Pers. P }
  26.    mfdb_fields = (addr1,addr2,wid_pix,ht_pix,wid_wds,flag,num_planes,r1,r2,r3);
  27.    mfdb = array[mfdb_fields] of integer;
  28.  
  29.   VAR
  30.     screen,backup : MFDB;       { one physical, one off-screen }
  31.     screen_buffer : scrn_memory;
  32.  
  33.     msg : Message_Buffer;       { stuff }
  34.     i,key,event : integer;
  35.  
  36.                 { these procedures must be in second module so that we can
  37.                   convert an address to integers }
  38. PROCEDURE init_form(var form : MFDB; var addr : scrn_memory); EXTERNAL;
  39. PROCEDURE copy_rect(var s,d : MFDB;
  40.                   from_x,from_y,to_x,to_y,wid,ht : integer);  EXTERNAL;
  41.  
  42.   {$I gemsubs}          { GEM subroutines }
  43.  
  44. { *************************************************************************** }
  45. { main program }
  46.  
  47.   BEGIN
  48.     IF Init_Gem >= 0 THEN
  49.       BEGIN
  50.          clear_screen;
  51.                 { put some background lines on screen }
  52.          Draw_mode(replace_mode);
  53.          Line_Color(Green);
  54.          Line_Style(Solid);
  55.          for i := 1 to 39 do begin
  56.             Line(i*16,0,i*16,200);
  57.             Line(0,i*5,640,i*5);
  58.          end;
  59.                 { put a figure on top of background }
  60.          Paint_Color(Red);
  61.          Paint_Style(Solid);
  62.          Paint_Rect(box_x,box_y,box_wid,box_ht);
  63.  
  64.                 { initialize screen form }
  65.          screen[addr1] := 0;    { the physical screen }
  66.          screen[addr2] := 0;
  67.  
  68.                 { initialize backup form }
  69.          init_form(backup,screen_buffer);
  70.  
  71.                 { now wait for key press }
  72.          event := Get_Event(E_Keyboard,0,0,0,0,false,0,0,0,0,
  73.                             false,0,0,0,0,msg,key,key,key,key,key,key);
  74.  
  75.                 { and copy stuff to backup screen in new location }
  76.          copy_rect(screen,backup,box_x,box_y,new_x,new_y,box_wid,box_ht);
  77.  
  78.                 { and wait for another key press }
  79.          event := Get_Event(E_Keyboard,0,0,0,0,false,0,0,0,0,
  80.                             false,0,0,0,0,msg,key,key,key,key,key,key);
  81.  
  82.                 { and copy back to screen }
  83.          copy_rect(backup,screen,new_x,new_y,new_x,new_y,box_wid,box_ht);
  84.  
  85.                 { and wait for another key press }
  86.          event := Get_Event(E_Keyboard,0,0,0,0,false,0,0,0,0,
  87.                           false,0,0,0,0,msg,key,key,key,key,key,key);
  88.          Exit_Gem ;
  89.       END ;
  90.   END.                          { Thats all folks }
  91. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə